package com.huiquan.vocab.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.huiquan.framework.base.EnhancedBaseDao;
import com.huiquan.vocab.domain.VocabDyadPre;
import com.huiquan.vocab.domain.VocabDyadStd;
import com.ibatis.sqlmap.client.SqlMapClient;

@Repository
public class VocabDyadDao extends EnhancedBaseDao<VocabDyadStd> {

	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "VOCAB_DYAD.";

	public VocabDyadDao() {
		super(space);
	}

	public void updateStdByDyad(String array, String partPattern, Long stdId) {
		Map<String, Object> param = new HashMap<>();
		param.put("stdId", stdId);
		param.put("array", array);
		param.put("partPattern", partPattern);

		this.update(space + "UDPATE_STD_BY_DYAD", param, sqlMapClient);
	}

	public void mergeStdIdByCnt(String ids, Long uid) {
		Map<String, Object> param = new HashMap<>();
		param.put("ids", ids);
		param.put("uid", uid);

		this.update(space + "MERGE_STD_ID_BY_CNT", param, sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<String> retrieveWrongPPArray() {
		return (List<String>) this.list(space + "RETRIEVE_WRONG_P_P_ARRAY", sqlMapClient);
	}

	public void initPrePO() {
		this.update(space + "INIT_PRE_P_O", sqlMapClient);
	}

	public void initPODyadByPre() {
		this.update(space + "INIT_P_O_DYAD_BY_PRE", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<VocabDyadPre> retrieveComplexPOPre() {

		return (List<VocabDyadPre>) this.list(space + "RETRIEVE_COMPLEX_P_O_PRE", sqlMapClient);
	}

	public void initPreOO() {
		this.update(space + "INIT_PRE_O_O", sqlMapClient);
	}

	public void initOODyadPre2() {
		this.update(space + "INIT_O_O_DYAD_PRE2", sqlMapClient);
	}

	public void initOODyadByPre3() {
		this.update(space + "INIT_O_O_DYAD_BY_PRE3", sqlMapClient);
	}

	public void initPreOS() {
		this.update(space + "INIT_PRE_O_S", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, String>> retrieveMultiOSPre() {

		return (List<Map<String, String>>) this.list(space + "RETRIEVE_MULTI_O_S_PRE", sqlMapClient);
	}

	public void initOSDyadByPre() {
		this.update(space + "INIT_O_S_DYAD_BY_PRE", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<String> retrieveMultiOCombineS() {

		return (List<String>) this.list(space + "RETRIEVE_MULTI_O_COMBINE_S", sqlMapClient);
	}
	
	public void updateStdId(String newStdId, String stdIds) {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("stdId", newStdId);
		param.put("stdIds", stdIds);
		this.update(space + "UPDATE_STD_ID", param, sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<String> retrievePOBlacklist4ExportRuleFile() {

		return (List<String>) this.list(space + "RETRIEVE_P_O_BLACKLIST_4_EXPORT_RULE_FILE", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<String> retrieveBlacklist4ExportRuleFile(String type) {

		return (List<String>) this.list(space + "RETRIEVE_BLACKLIST_4_EXPORT_RULE_FILE", type, sqlMapClient);
	}
	@SuppressWarnings("unchecked")
	public List<String> retrieveElementSynonymO4ExportRuleFile() {

		return (List<String>) this.list(space + "RETRIEVE_ELEMENT_SYNONYM_O_4_EXPORT_RULE_FILE", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<String> retrievePOMerge4ExportRuleFile() {

		return (List<String>) this.list(space + "RETRIEVE_P_O_MERGE_4_EXPORT_RULE_FILE", sqlMapClient);
	}

	public void initStdArray() {
		this.update(space + "INIT_STD_ARRAY", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, String>> retrieveCheckedArrayAndStdDyad() {

		return (List<Map<String, String>>) this.list(space + "RETRIEVE_CHECKED_ARRAY_AND_STD_DYAD", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, String>> retrieveOSIgnoreP() {

		return (List<Map<String, String>>) this.list(space + "RETRIEVE_O_S_IGNORE_P", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, String>> retrieveSymptomAndStd() {

		return (List<Map<String, String>>) this.list(space + "RETRIEVE_SYMPTOM_AND_STD", sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<String> retrieveBlacklistAndProp4ExportRuleFile(String type) {

		return (List<String>) this.list(space + "RETRIEVE_BLACKLIST_AND_PROP_4_EXPORT_RULE_FILE", type, sqlMapClient);
	}

	@SuppressWarnings("unchecked")
	public List<Map<String, String>> retrieveSi2OS() {
		
		return (List<Map<String, String>>) this.list(space + "RETRIEVE_SI_2_OS", sqlMapClient);
	}

	public int mergeTrueDyadByElementStd() {
		
		return this.update(space + "MERGE_TRUE_DYAD_BY_ELEMENT_STD", sqlMapClient);
	}

	public void initOSIgnoreP() {
		
		this.update(space + "INIT_O_S_IGNORE_P", sqlMapClient);
	}

	public void initStdArrayByRule() {

		this.update(space + "INIT_STD_ARRAY_BY_RULE", sqlMapClient);
	}
	public VocabDyadPre retrieveByDyadProperties(String type, String array, String partPattern) {
		Map<String, Object> param = new HashMap<>();
		param.put("type", type);
		param.put("array", array);
		param.put("partPattern", partPattern);

		return (VocabDyadPre) this.object(space + "RETRIEVE_BY_DYAD_PROPERTIES", param, sqlMapClient);
	}
	@SuppressWarnings("unchecked")
	public List<Map<String, String>> retrieveDyadAndStd() {
		
		return (List<Map<String, String>>) this.list(space + "RETRIEVE_DYAD_AND_STD", sqlMapClient);
	}


	public List<String> retrieveBlacklistR() {

		return (List<String>) this.list(space + "RETRIEVE_BLACKLIST_R",  sqlMapClient);
	}
}
